# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[return UNIVERSE_NAME_DICT[self.type]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92e212c>}
nname: 0
n 0(None)[return '%d' % len(self.radio_services)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92e230c>}
nname: 0
n 0(None)[return '%d' % len(self.video_services)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbfec>}
nname: 0
n 0(None)[return self.get_item_list('radio_services')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbf6c>}
nname: 0
n 0(None)[return self.get_item_list('video_services')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbfcc>}
nname: 61
n 61(None)[return '%d%%' % 0
]:
	i: 22(), 57()
	o: 

nname: 57
n 57(None)[]:
	i: 0(f)
	o: 61()

nname: 22
n 22(None)[]:
	i: 0(t)
	o: 61()

nname: 0
n 0(self.scan_status[0] > 0)[]:
	i: 
	o: 22(t), 57(f)

nname: 0
n 0(None)[if self.scan_status[0] > 0:
	pass
return '%d%%' % 0
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92e24ac>}
nname: 0
n 0(None)[return dict(pos=self.scan_status[0], max=self.scan_status[1])
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbe2c>}
nname: 0
n 0(None)[return '%d%%' % self.scan_status[3]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbe2c>}
nname: 0
n 0(None)[return dict(pos=self.scan_status[3], max=100)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbf8c>}
nname: 0
n 0(None)[return '%d%%' % self.scan_status[2]
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbf6c>}
nname: 0
n 0(None)[return dict(pos=self.scan_status[2], max=100)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92dbf8c>}
nname: 0
n 0(None)[Player.__init__(self, 'channelscanner')
self.scan_status = [0, 0, 0, 0]
self.eventhandler = ChannelScannerEventHandler(self)
self.set_items([], list_name='video_services')
self.set_items([], list_name='radio_services')
self._new_services = False
self.video_services = []
self.radio_services = []
self._running = False
self._message_window = LoadingWindow()
self._getitems_keywords.update(dict(signal_strength_progress_bar=(lambda : dict(pos=self.scan_status[2], max=100)), signal_strength=(lambda : '%d%%' % self.scan_status[2]), signal_noise_ratio_progress_bar=(lambda : dict(pos=self.scan_status[3], max=100)), signal_noise_ratio=(lambda : '%d%%' % self.scan_status[3]), scan_progressbar=(lambda : dict(pos=self.scan_status[0], max=self.scan_status[1])), scan_progress=(lambda : .scan_status[0] > 0:
	pass
return '%d%%' % 0), video_services_list=(lambda : self.get_item_list('video_services')), radio_services_list=(lambda : self.get_item_list('radio_services')), nb_video_services=(lambda : '%d' % len(self.video_services)), nb_radio_services=(lambda : '%d' % len(self.radio_services)), scan_name=(lambda : UNIVERSE_NAME_DICT[self.type])))
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d59ec>}
nname: 339
n 339(None)[self._running = False
self._waiting_for_commit = False
]:
	i: 270(), 325()
	o: 

nname: 325
n 325(None)[self.wyscanserver.RemoveAllServices()
]:
	i: 185(f)
	o: 339()

nname: 270
n 270(None)[self._stop()
MessageWindow(title=_('Error'), text=_('Scan impossible')).show()
]:
	i: 185(t)
	o: 339()

nname: 185
n 185(ret_scan)[self.wyscanserver.ConfigurePermanentScan(item.include_scrambled, False)
ret_scan = self.wyscanserver.StartScan(item.antenna[7], item.antenna[6], item.transponder[0], item.scan_network, item.include_scrambled)
]:
	i: 55(), 184()
	o: 270(t), 325(f)

nname: 184
n 184(None)[]:
	i: 0(f)
	o: 185()

nname: 55
n 55(None)[self.wyscanserver = self.selected.wyscanserver
self.wyscanserver.errorCallback.register(self.dbus_error_callback)
self.wyscanserver.eventCallback.register(self.dbus_event_callback)
self.wyscanserver.scanEventCallback.register(self.dbus_scan_callback)
self.wyscanserver.serviceUpdateCallback.register(self.dbus_scan_service_found_callback)
self.wyscanserver.scanProgression.register(self.dbus_scan_progression)
]:
	i: 0(t)
	o: 185()

nname: 0
n 0(self.wyscanserver is not self.selected.wyscanserver)[Player.play(self, item, playlist, hide_previous_menu=hide_previous_menu)
ChannelScanner._back_main_menu = False
]:
	i: 
	o: 55(t), 184(f)

nname: 339
n 339(None)[self._running = False
self._waiting_for_commit = False
]:
	i: 0()
	o: 

nname: 0
n 0(None)[Player.play(self, item, playlist, hide_previous_menu=hide_previous_menu)
ChannelScanner._back_main_menu = False
if self.wyscanserver is not self.selected.wyscanserver:
	self.wyscanserver = self.selected.wyscanserver
	self.wyscanserver.errorCallback.register(self.dbus_error_callback)
	self.wyscanserver.eventCallback.register(self.dbus_event_callback)
	self.wyscanserver.scanEventCallback.register(self.dbus_scan_callback)
	self.wyscanserver.serviceUpdateCallback.register(self.dbus_scan_service_found_callback)
	self.wyscanserver.scanProgression.register(self.dbus_scan_progression)
self.wyscanserver.ConfigurePermanentScan(item.include_scrambled, False)
ret_scan = self.wyscanserver.StartScan(item.antenna[7], item.antenna[6], item.transponder[0], item.scan_network, item.include_scrambled)
if ret_scan:
	self._stop()
	MessageWindow(title=_('Error'), text=_('Scan impossible')).show()
else:
	self.wyscanserver.RemoveAllServices()
]:
	i: 
	o: 339()

nname: 0
n 0(None)[Player.play(self, item, playlist, hide_previous_menu=hide_previous_menu)
ChannelScanner._back_main_menu = False
if self.wyscanserver is not self.selected.wyscanserver:
	self.wyscanserver = self.selected.wyscanserver
	self.wyscanserver.errorCallback.register(self.dbus_error_callback)
	self.wyscanserver.eventCallback.register(self.dbus_event_callback)
	self.wyscanserver.scanEventCallback.register(self.dbus_scan_callback)
	self.wyscanserver.serviceUpdateCallback.register(self.dbus_scan_service_found_callback)
	self.wyscanserver.scanProgression.register(self.dbus_scan_progression)
self.wyscanserver.ConfigurePermanentScan(item.include_scrambled, False)
ret_scan = self.wyscanserver.StartScan(item.antenna[7], item.antenna[6], item.transponder[0], item.scan_network, item.include_scrambled)
if ret_scan:
	self._stop()
	MessageWindow(title=_('Error'), text=_('Scan impossible')).show()
else:
	self.wyscanserver.RemoveAllServices()
self._running = False
self._waiting_for_commit = False
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d5dac>}
nname: 0
n 0(None)[log.warning('ERROR %s %s', args, kw)
self._stop()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d0d2c>}
nname: 0
n 0(None)[log.debug('EVENT %s %s', args, kw)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d0e0c>}
nname: 145
n 145(None)[]:
	i: 55(), 81(), 117(), 144()
	o: 

nname: 144
n 144(None)[]:
	i: 104(f)
	o: 145()

nname: 117
n 117(None)[self._message_window.hide()
self._stop()
]:
	i: 104(t)
	o: 145()

nname: 104
n 104(nEventID == 3)[]:
	i: 68(f)
	o: 117(t), 144(f)

nname: 81
n 81(None)[self._running = False
self.prompt_for_commit()
]:
	i: 68(t)
	o: 145()

nname: 68
n 68(nEventID == 2)[]:
	i: 43(f)
	o: 81(t), 104(f)

nname: 55
n 55(None)[self._running = True
]:
	i: 43(t)
	o: 145()

nname: 43
n 43(nEventID == 1)[]:
	i: 34(), 42()
	o: 55(t), 68(f)

nname: 42
n 42(None)[]:
	i: 0(f)
	o: 43()

nname: 34
n 34(None)[]:
	i: 0(t)
	o: 43()

nname: 0
n 0(nDeviceID != self.selected.antenna[7])[nDeviceID, nEventID = args
]:
	i: 
	o: 34(t), 42(f)

nname: 145
n 145(None)[]:
	i: 0()
	o: 

nname: 0
n 0(None)[nDeviceID, nEventID = args
if nDeviceID != self.selected.antenna[7]:
	pass
if nEventID == 1:
	self._running = True
else:
	if nEventID == 2:
		self._running = False
		self.prompt_for_commit()
	else:
		if nEventID == 3:
			self._message_window.hide()
			self._stop()
]:
	i: 
	o: 145()

nname: 0
n 0(None)[nDeviceID, nEventID = args
if nDeviceID != self.selected.antenna[7]:
	pass
if nEventID == 1:
	self._running = True
else:
	if nEventID == 2:
		self._running = False
		self.prompt_for_commit()
	else:
		if nEventID == 3:
			self._message_window.hide()
			self._stop()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d5e4c>}
nname: 0
n 0(None)[def _callback(self, *args, **args):
	nDeviceID, nEventID = args
	if nDeviceID != self.selected.antenna[7]:
		pass
	if nEventID == 1:
		self._running = True
	else:
		if nEventID == 2:
			self._running = False
			self.prompt_for_commit()
		else:
			if nEventID == 3:
				self._message_window.hide()
				self._stop()

log.debug('SCAN EVENT CALLBACK %s %s', args, kw)
Task(_callback, self, *args, **kw).start(0.10000000000000001)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d0cac>}
nname: 0
n 0(None)[]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d0b6c>}
nname: 0
n 0(None)[self.wyscanserver.errorCallback.unregister(self.dbus_error_callback)
self.wyscanserver.eventCallback.unregister(self.dbus_event_callback)
self.wyscanserver.scanEventCallback.unregister(self.dbus_scan_callback)
self.wyscanserver.serviceUpdateCallback.unregister(self.dbus_scan_service_found_callback)
self.wyscanserver.scanProgression.unregister(self.dbus_scan_progression)
self.wyscanserver = None
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d56ac>}
nname: 284
n 284(None)[]:
	i: 266(), 270(), 283(AE)
	o: 

nname: 270
n 270(None)[PRINT_EXCEPTION()
]:
	i: 0(except)
	o: 284()

nname: 266
n 266(None)[]:
	i: 159(), 221(), 239()
	o: 284()

nname: 239
n 239(None)[ms.back_one_menu()
louie_send('tv_scan_finished', sender='tv')
]:
	i: 195(f)
	o: 266()

nname: 221
n 221(None)[ms.back_to_home()
]:
	i: 195(t)
	o: 266()

nname: 195
n 195(len(pygui_globs['menustack'].menus_stack) <= 2)[]:
	i: 124&137(f)
	o: 221(t), 239(f)

nname: 159
n 159(None)[ms.back_to_home(safe=False)
ms.get_root().launch_tv()
]:
	i: 124&137(t)
	o: 266()

nname: 124&137
n 124&137(not ms.is_on_firstboot() and len(self.video_services) > 0)[]:
	i: 105(), 123()
	o: 159(t), 195(f)

nname: 123
n 123(None)[]:
	i: 86(f)
	o: 124&137()

nname: 105
n 105(None)[ms.back_to_home()
]:
	i: 86(t)
	o: 124&137()

nname: 86
n 86(ChannelScanner._back_main_menu)[self.unregister_wyscan_callbacks()
]:
	i: 0(try)
	o: 105(t), 123(f)

nname: 0
n 0(None)[self.scan_status = [0, 0, 0, 0]
louie_send('scan_progress', sender=self, value=self['scan_progress'])
louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
ms = pygui_globs['menustack']
]:
	i: 
	o: 86(try), 270(except)

nname: 284
n 284(None)[]:
	i: 270(), 124&137()
	o: 

nname: 270
n 270(None)[except:
	PRINT_EXCEPTION()
]:
	i: 0()
	o: 284()

nname: 124&137
n 124&137(None)[if not ms.is_on_firstboot() and len(self.video_services) > 0:
	ms.back_to_home(safe=False)
	ms.get_root().launch_tv()
else:
	if len(pygui_globs['menustack'].menus_stack) <= 2:
		ms.back_to_home()
	else:
		ms.back_one_menu()
		louie_send('tv_scan_finished', sender='tv')
]:
	i: 0()
	o: 284()

nname: 0
n 0(None)[self.scan_status = [0, 0, 0, 0]
louie_send('scan_progress', sender=self, value=self['scan_progress'])
louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
ms = pygui_globs['menustack']
try:
	self.unregister_wyscan_callbacks()
	if ChannelScanner._back_main_menu:
		ms.back_to_home()
]:
	i: 
	o: 124&137(), 270()

self.nodes: {0: <unpyclib.structure.node instance at 0x92e2c0c>, '124&137': <unpyclib.structure.node instance at 0x92e2fac>, 284: <unpyclib.structure.node instance at 0x92db4ac>, 270: <unpyclib.structure.node instance at 0x92dbbcc>}
nname: 0
n 0(None)[self.wyscanserver.StopScan(self.selected.antenna[7])
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d0f2c>}
nname: 120
n 120(None)[]:
	i: 75(), 119()
	o: 

nname: 119
n 119(None)[]:
	i: 66(f)
	o: 120()

nname: 75
n 75(None)[self.wyscanserver.RollbackScan(self.selected.antenna[7])
self.unregister_wyscan_callbacks()
]:
	i: 66(t)
	o: 120()

nname: 66
n 66(self._waiting_for_commit)[]:
	i: 22(), 65()
	o: 75(t), 119(f)

nname: 65
n 65(None)[]:
	i: 0(f)
	o: 66()

nname: 22
n 22(None)[ChannelScanner._back_main_menu = True
self.wyscanserver.StopScan(self.selected.antenna[7])
]:
	i: 0(t)
	o: 66()

nname: 0
n 0(self._running)[Player.stop(self)
]:
	i: 
	o: 22(t), 65(f)

nname: 120
n 120(None)[]:
	i: 0()
	o: 

nname: 0
n 0(None)[Player.stop(self)
if self._running:
	ChannelScanner._back_main_menu = True
	self.wyscanserver.StopScan(self.selected.antenna[7])
if self._waiting_for_commit:
	self.wyscanserver.RollbackScan(self.selected.antenna[7])
	self.unregister_wyscan_callbacks()
]:
	i: 
	o: 120()

nname: 0
n 0(None)[Player.stop(self)
if self._running:
	ChannelScanner._back_main_menu = True
	self.wyscanserver.StopScan(self.selected.antenna[7])
if self._waiting_for_commit:
	self.wyscanserver.RollbackScan(self.selected.antenna[7])
	self.unregister_wyscan_callbacks()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92e238c>}
nname: 0
n 0(None)[self.wyscanserver.RollbackScan(self.selected.antenna[7])
ChannelScanner._back_main_menu = True
self._stop()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92d572c>}
nname: 33
n 33(None)[self.wyscanserver.CommitScan(self.selected.antenna[7])
user_config['tv']['last_scan_time'] = time()
user_config.save()
self._message_window.show()
return None
]:
	i: 15(), 32()
	o: 

nname: 32
n 32(None)[]:
	i: 0(f)
	o: 33()

nname: 15
n 15(None)[ChannelItem.player.clear_last_zap()
]:
	i: 0(t)
	o: 33()

nname: 0
n 0(ChannelItem.player is not None)[]:
	i: 
	o: 15(t), 32(f)

nname: 0
n 0(None)[if ChannelItem.player is not None:
	ChannelItem.player.clear_last_zap()
self.wyscanserver.CommitScan(self.selected.antenna[7])
user_config['tv']['last_scan_time'] = time()
user_config.save()
self._message_window.show()
return None
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92db8cc>}
nname: 183
n 183(None)[self._waiting_for_commit = True
def _rollback():
	self.wyscanserver.RollbackScan(self.selected.antenna[7])
	ChannelScanner._back_main_menu = True
	self._stop()

def _commit():
	if ChannelItem.player is not None:
		ChannelItem.player.clear_last_zap()
	self.wyscanserver.CommitScan(self.selected.antenna[7])
	user_config['tv']['last_scan_time'] = time()
	user_config.save()
	self._message_window.show()
	return None

message = _('%(num_services)i channels found. Do you want to save them ?')
values = {'num_services': num_services}
button = Button(_('OK'), True)
button.connect(_commit)
cancel_button = Button(_('No'), False)
cancel_button.connect(_rollback)
w = ConfirmWindow(text=message % values, buttons=[button, cancel_button])
Task(w.show).start(0.5)
]:
	i: 138(), 182()
	o: 

nname: 182
n 182(None)[]:
	i: 0&128(f)
	o: 183()

nname: 138
n 138(None)[self.wyscanserver.RollbackScan(self.selected.antenna[7])
self._stop()
]:
	i: 0&128(t)
	o: 183()

nname: 0&128
n 0&128(num_services == 0 or ChannelScanner._back_main_menu)[device_id = self.selected.antenna[7]
self.scan_status[0] = self.scan_status[1]
louie_send('scan_progress', sender=self, value=self['scan_progress'])
louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
num_services = len(self.radio_services) + len(self.video_services)
]:
	i: 
	o: 138(t), 182(f)

nname: 0&128
n 0&128(None)[device_id = self.selected.antenna[7]
self.scan_status[0] = self.scan_status[1]
louie_send('scan_progress', sender=self, value=self['scan_progress'])
louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
num_services = len(self.radio_services) + len(self.video_services)
if num_services == 0 or ChannelScanner._back_main_menu:
	self.wyscanserver.RollbackScan(self.selected.antenna[7])
	self._stop()
self._waiting_for_commit = True
def _rollback():
	self.wyscanserver.RollbackScan(self.selected.antenna[7])
	ChannelScanner._back_main_menu = True
	self._stop()

def _commit():
	if ChannelItem.player is not None:
		ChannelItem.player.clear_last_zap()
	self.wyscanserver.CommitScan(self.selected.antenna[7])
	user_config['tv']['last_scan_time'] = time()
	user_config.save()
	self._message_window.show()
	return None

message = _('%(num_services)i channels found. Do you want to save them ?')
values = {'num_services': num_services}
button = Button(_('OK'), True)
button.connect(_commit)
cancel_button = Button(_('No'), False)
cancel_button.connect(_rollback)
w = ConfirmWindow(text=message % values, buttons=[button, cancel_button])
Task(w.show).start(0.5)
]:
	i: 
	o: 

self.nodes: {'0&128': <unpyclib.structure.node instance at 0x92db6ac>}
nname: 6
n 6(None)[__doc__ = 'ChannelScanner interface.\n    Used for DVB-S and DVB-T scan.\n    '
wyscanserver = None
_back_main_menu = False
_waiting_for_commit = False
def __init__(self, type='channelscanner'):
	Player.__init__(self, 'channelscanner')
	self.scan_status = [0, 0, 0, 0]
	self.eventhandler = ChannelScannerEventHandler(self)
	self.set_items([], list_name='video_services')
	self.set_items([], list_name='radio_services')
	self._new_services = False
	self.video_services = []
	self.radio_services = []
	self._running = False
	self._message_window = LoadingWindow()
	self._getitems_keywords.update(dict(signal_strength_progress_bar=(lambda : dict(pos=self.scan_status[2], max=100)), signal_strength=(lambda : '%d%%' % self.scan_status[2]), signal_noise_ratio_progress_bar=(lambda : dict(pos=self.scan_status[3], max=100)), signal_noise_ratio=(lambda : '%d%%' % self.scan_status[3]), scan_progressbar=(lambda : dict(pos=self.scan_status[0], max=self.scan_status[1])), scan_progress=(lambda : .scan_status[0] > 0:
		pass
	return '%d%%' % 0), video_services_list=(lambda : self.get_item_list('video_services')), radio_services_list=(lambda : self.get_item_list('radio_services')), nb_video_services=(lambda : '%d' % len(self.video_services)), nb_radio_services=(lambda : '%d' % len(self.radio_services)), scan_name=(lambda : UNIVERSE_NAME_DICT[self.type])))

def play(self, item, playlist=None, hide_previous_menu=True):
	Player.play(self, item, playlist, hide_previous_menu=hide_previous_menu)
	ChannelScanner._back_main_menu = False
	if self.wyscanserver is not self.selected.wyscanserver:
		self.wyscanserver = self.selected.wyscanserver
		self.wyscanserver.errorCallback.register(self.dbus_error_callback)
		self.wyscanserver.eventCallback.register(self.dbus_event_callback)
		self.wyscanserver.scanEventCallback.register(self.dbus_scan_callback)
		self.wyscanserver.serviceUpdateCallback.register(self.dbus_scan_service_found_callback)
		self.wyscanserver.scanProgression.register(self.dbus_scan_progression)
	self.wyscanserver.ConfigurePermanentScan(item.include_scrambled, False)
	ret_scan = self.wyscanserver.StartScan(item.antenna[7], item.antenna[6], item.transponder[0], item.scan_network, item.include_scrambled)
	if ret_scan:
		self._stop()
		MessageWindow(title=_('Error'), text=_('Scan impossible')).show()
	else:
		self.wyscanserver.RemoveAllServices()
	self._running = False
	self._waiting_for_commit = False

def dbus_error_callback(self, *args, **args):
	log.warning('ERROR %s %s', args, kw)
	self._stop()

def dbus_event_callback(self, *args, **args):
	log.debug('EVENT %s %s', args, kw)

def dbus_scan_callback(self, *args, **args):
	def _callback(self, *args, **args):
		nDeviceID, nEventID = args
		if nDeviceID != self.selected.antenna[7]:
			pass
		if nEventID == 1:
			self._running = True
		else:
			if nEventID == 2:
				self._running = False
				self.prompt_for_commit()
			else:
				if nEventID == 3:
					self._message_window.hide()
					self._stop()

	log.debug('SCAN EVENT CALLBACK %s %s', args, kw)
	Task(_callback, self, *args, **kw).start(0.10000000000000001)

dbus_scan_progression = tasked(0.10000000000000001)()
dbus_scan_service_found_callback = tasked(0.10000000000000001)()
_update_services = selective_gui_updater('nb_video_services', 'nb_radio_services')()
def tick_callback(self):
	pass

def unregister_wyscan_callbacks(self):
	self.wyscanserver.errorCallback.unregister(self.dbus_error_callback)
	self.wyscanserver.eventCallback.unregister(self.dbus_event_callback)
	self.wyscanserver.scanEventCallback.unregister(self.dbus_scan_callback)
	self.wyscanserver.serviceUpdateCallback.unregister(self.dbus_scan_service_found_callback)
	self.wyscanserver.scanProgression.unregister(self.dbus_scan_progression)
	self.wyscanserver = None
	return None

def _stop(self):
	self.scan_status = [0, 0, 0, 0]
	louie_send('scan_progress', sender=self, value=self['scan_progress'])
	louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
	ms = pygui_globs['menustack']
	try:
		self.unregister_wyscan_callbacks()
		if ChannelScanner._back_main_menu:
			ms.back_to_home()

def process_stop(self):
	self.wyscanserver.StopScan(self.selected.antenna[7])

def stop(self):
	Player.stop(self)
	if self._running:
		ChannelScanner._back_main_menu = True
		self.wyscanserver.StopScan(self.selected.antenna[7])
	if self._waiting_for_commit:
		self.wyscanserver.RollbackScan(self.selected.antenna[7])
		self.unregister_wyscan_callbacks()

def prompt_for_commit(self):
	device_id = self.selected.antenna[7]
	self.scan_status[0] = self.scan_status[1]
	louie_send('scan_progress', sender=self, value=self['scan_progress'])
	louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
	num_services = len(self.radio_services) + len(self.video_services)
	if num_services == 0 or ChannelScanner._back_main_menu:
		self.wyscanserver.RollbackScan(self.selected.antenna[7])
		self._stop()
	self._waiting_for_commit = True
	def _rollback():
		self.wyscanserver.RollbackScan(self.selected.antenna[7])
		ChannelScanner._back_main_menu = True
		self._stop()

	def _commit():
		if ChannelItem.player is not None:
			ChannelItem.player.clear_last_zap()
		self.wyscanserver.CommitScan(self.selected.antenna[7])
		user_config['tv']['last_scan_time'] = time()
		user_config.save()
		self._message_window.show()
		return None

	message = _('%(num_services)i channels found. Do you want to save them ?')
	values = {'num_services': num_services}
	button = Button(_('OK'), True)
	button.connect(_commit)
	cancel_button = Button(_('No'), False)
	cancel_button.connect(_rollback)
	w = ConfirmWindow(text=message % values, buttons=[button, cancel_button])
	Task(w.show).start(0.5)

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0x92d070c>}
nname: 0
n 0(None)[from __future__ import absolute_import
from time import time
from peewee.debug import PRINT_EXCEPTION, GET_LOGGER
from peewee.messages import send as louie_send
from peewee.notifier import Task, tasked
from wyrecord.callbacks import UPDATE_SERVICE_ADDED, UPDATE_SERVICE_UPDATED, UPDATE_SERVICE_REMOVED
from pygui.config import user_config
from pygui.eventmanager.menus import ChannelScannerEventHandler
from pygui.shared import pygui_globs
from pygui.window import TextWindow, ConfirmWindow, Button, LoadingWindow, MessageWindow
from pygui.menu import selective_gui_updater, UNIVERSE_NAME_DICT
from pygui.item.core import Item
from pygui.item.mediaitem import ChannelItem
from .core import Player
log = GET_LOGGER(__name__)
class ChannelScanner(Player):
	__doc__ = 'ChannelScanner interface.\n    Used for DVB-S and DVB-T scan.\n    '
	wyscanserver = None
	_back_main_menu = False
	_waiting_for_commit = False
	def __init__(self, type='channelscanner'):
		Player.__init__(self, 'channelscanner')
		self.scan_status = [0, 0, 0, 0]
		self.eventhandler = ChannelScannerEventHandler(self)
		self.set_items([], list_name='video_services')
		self.set_items([], list_name='radio_services')
		self._new_services = False
		self.video_services = []
		self.radio_services = []
		self._running = False
		self._message_window = LoadingWindow()
		self._getitems_keywords.update(dict(signal_strength_progress_bar=(lambda : dict(pos=self.scan_status[2], max=100)), signal_strength=(lambda : '%d%%' % self.scan_status[2]), signal_noise_ratio_progress_bar=(lambda : dict(pos=self.scan_status[3], max=100)), signal_noise_ratio=(lambda : '%d%%' % self.scan_status[3]), scan_progressbar=(lambda : dict(pos=self.scan_status[0], max=self.scan_status[1])), scan_progress=(lambda : .scan_status[0] > 0:
			pass
		return '%d%%' % 0), video_services_list=(lambda : self.get_item_list('video_services')), radio_services_list=(lambda : self.get_item_list('radio_services')), nb_video_services=(lambda : '%d' % len(self.video_services)), nb_radio_services=(lambda : '%d' % len(self.radio_services)), scan_name=(lambda : UNIVERSE_NAME_DICT[self.type])))

	def play(self, item, playlist=None, hide_previous_menu=True):
		Player.play(self, item, playlist, hide_previous_menu=hide_previous_menu)
		ChannelScanner._back_main_menu = False
		if self.wyscanserver is not self.selected.wyscanserver:
			self.wyscanserver = self.selected.wyscanserver
			self.wyscanserver.errorCallback.register(self.dbus_error_callback)
			self.wyscanserver.eventCallback.register(self.dbus_event_callback)
			self.wyscanserver.scanEventCallback.register(self.dbus_scan_callback)
			self.wyscanserver.serviceUpdateCallback.register(self.dbus_scan_service_found_callback)
			self.wyscanserver.scanProgression.register(self.dbus_scan_progression)
		self.wyscanserver.ConfigurePermanentScan(item.include_scrambled, False)
		ret_scan = self.wyscanserver.StartScan(item.antenna[7], item.antenna[6], item.transponder[0], item.scan_network, item.include_scrambled)
		if ret_scan:
			self._stop()
			MessageWindow(title=_('Error'), text=_('Scan impossible')).show()
		else:
			self.wyscanserver.RemoveAllServices()
		self._running = False
		self._waiting_for_commit = False

	def dbus_error_callback(self, *args, **args):
		log.warning('ERROR %s %s', args, kw)
		self._stop()

	def dbus_event_callback(self, *args, **args):
		log.debug('EVENT %s %s', args, kw)

	def dbus_scan_callback(self, *args, **args):
		def _callback(self, *args, **args):
			nDeviceID, nEventID = args
			if nDeviceID != self.selected.antenna[7]:
				pass
			if nEventID == 1:
				self._running = True
			else:
				if nEventID == 2:
					self._running = False
					self.prompt_for_commit()
				else:
					if nEventID == 3:
						self._message_window.hide()
						self._stop()

		log.debug('SCAN EVENT CALLBACK %s %s', args, kw)
		Task(_callback, self, *args, **kw).start(0.10000000000000001)

	dbus_scan_progression = tasked(0.10000000000000001)()
	dbus_scan_service_found_callback = tasked(0.10000000000000001)()
	_update_services = selective_gui_updater('nb_video_services', 'nb_radio_services')()
	def tick_callback(self):
		pass

	def unregister_wyscan_callbacks(self):
		self.wyscanserver.errorCallback.unregister(self.dbus_error_callback)
		self.wyscanserver.eventCallback.unregister(self.dbus_event_callback)
		self.wyscanserver.scanEventCallback.unregister(self.dbus_scan_callback)
		self.wyscanserver.serviceUpdateCallback.unregister(self.dbus_scan_service_found_callback)
		self.wyscanserver.scanProgression.unregister(self.dbus_scan_progression)
		self.wyscanserver = None
		return None

	def _stop(self):
		self.scan_status = [0, 0, 0, 0]
		louie_send('scan_progress', sender=self, value=self['scan_progress'])
		louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
		ms = pygui_globs['menustack']
		try:
			self.unregister_wyscan_callbacks()
			if ChannelScanner._back_main_menu:
				ms.back_to_home()

	def process_stop(self):
		self.wyscanserver.StopScan(self.selected.antenna[7])

	def stop(self):
		Player.stop(self)
		if self._running:
			ChannelScanner._back_main_menu = True
			self.wyscanserver.StopScan(self.selected.antenna[7])
		if self._waiting_for_commit:
			self.wyscanserver.RollbackScan(self.selected.antenna[7])
			self.unregister_wyscan_callbacks()

	def prompt_for_commit(self):
		device_id = self.selected.antenna[7]
		self.scan_status[0] = self.scan_status[1]
		louie_send('scan_progress', sender=self, value=self['scan_progress'])
		louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
		num_services = len(self.radio_services) + len(self.video_services)
		if num_services == 0 or ChannelScanner._back_main_menu:
			self.wyscanserver.RollbackScan(self.selected.antenna[7])
			self._stop()
		self._waiting_for_commit = True
		def _rollback():
			self.wyscanserver.RollbackScan(self.selected.antenna[7])
			ChannelScanner._back_main_menu = True
			self._stop()

		def _commit():
			if ChannelItem.player is not None:
				ChannelItem.player.clear_last_zap()
			self.wyscanserver.CommitScan(self.selected.antenna[7])
			user_config['tv']['last_scan_time'] = time()
			user_config.save()
			self._message_window.show()
			return None

		message = _('%(num_services)i channels found. Do you want to save them ?')
		values = {'num_services': num_services}
		button = Button(_('OK'), True)
		button.connect(_commit)
		cancel_button = Button(_('No'), False)
		cancel_button.connect(_rollback)
		w = ConfirmWindow(text=message % values, buttons=[button, cancel_button])
		Task(w.show).start(0.5)



]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0x92c342c>}
from __future__ import absolute_import
from time import time
from peewee.debug import PRINT_EXCEPTION, GET_LOGGER
from peewee.messages import send as louie_send
from peewee.notifier import Task, tasked
from wyrecord.callbacks import UPDATE_SERVICE_ADDED, UPDATE_SERVICE_UPDATED, UPDATE_SERVICE_REMOVED
from pygui.config import user_config
from pygui.eventmanager.menus import ChannelScannerEventHandler
from pygui.shared import pygui_globs
from pygui.window import TextWindow, ConfirmWindow, Button, LoadingWindow, MessageWindow
from pygui.menu import selective_gui_updater, UNIVERSE_NAME_DICT
from pygui.item.core import Item
from pygui.item.mediaitem import ChannelItem
from .core import Player
log = GET_LOGGER(__name__)
class ChannelScanner(Player):
	__doc__ = 'ChannelScanner interface.\n    Used for DVB-S and DVB-T scan.\n    '
	wyscanserver = None
	_back_main_menu = False
	_waiting_for_commit = False
	def __init__(self, type='channelscanner'):
		Player.__init__(self, 'channelscanner')
		self.scan_status = [0, 0, 0, 0]
		self.eventhandler = ChannelScannerEventHandler(self)
		self.set_items([], list_name='video_services')
		self.set_items([], list_name='radio_services')
		self._new_services = False
		self.video_services = []
		self.radio_services = []
		self._running = False
		self._message_window = LoadingWindow()
		self._getitems_keywords.update(dict(signal_strength_progress_bar=(lambda : dict(pos=self.scan_status[2], max=100)), signal_strength=(lambda : '%d%%' % self.scan_status[2]), signal_noise_ratio_progress_bar=(lambda : dict(pos=self.scan_status[3], max=100)), signal_noise_ratio=(lambda : '%d%%' % self.scan_status[3]), scan_progressbar=(lambda : dict(pos=self.scan_status[0], max=self.scan_status[1])), scan_progress=(lambda : .scan_status[0] > 0:
			pass
		return '%d%%' % 0), video_services_list=(lambda : self.get_item_list('video_services')), radio_services_list=(lambda : self.get_item_list('radio_services')), nb_video_services=(lambda : '%d' % len(self.video_services)), nb_radio_services=(lambda : '%d' % len(self.radio_services)), scan_name=(lambda : UNIVERSE_NAME_DICT[self.type])))

	def play(self, item, playlist=None, hide_previous_menu=True):
		Player.play(self, item, playlist, hide_previous_menu=hide_previous_menu)
		ChannelScanner._back_main_menu = False
		if self.wyscanserver is not self.selected.wyscanserver:
			self.wyscanserver = self.selected.wyscanserver
			self.wyscanserver.errorCallback.register(self.dbus_error_callback)
			self.wyscanserver.eventCallback.register(self.dbus_event_callback)
			self.wyscanserver.scanEventCallback.register(self.dbus_scan_callback)
			self.wyscanserver.serviceUpdateCallback.register(self.dbus_scan_service_found_callback)
			self.wyscanserver.scanProgression.register(self.dbus_scan_progression)
		self.wyscanserver.ConfigurePermanentScan(item.include_scrambled, False)
		ret_scan = self.wyscanserver.StartScan(item.antenna[7], item.antenna[6], item.transponder[0], item.scan_network, item.include_scrambled)
		if ret_scan:
			self._stop()
			MessageWindow(title=_('Error'), text=_('Scan impossible')).show()
		else:
			self.wyscanserver.RemoveAllServices()
		self._running = False
		self._waiting_for_commit = False

	def dbus_error_callback(self, *args, **args):
		log.warning('ERROR %s %s', args, kw)
		self._stop()

	def dbus_event_callback(self, *args, **args):
		log.debug('EVENT %s %s', args, kw)

	def dbus_scan_callback(self, *args, **args):
		def _callback(self, *args, **args):
			nDeviceID, nEventID = args
			if nDeviceID != self.selected.antenna[7]:
				pass
			if nEventID == 1:
				self._running = True
			else:
				if nEventID == 2:
					self._running = False
					self.prompt_for_commit()
				else:
					if nEventID == 3:
						self._message_window.hide()
						self._stop()

		log.debug('SCAN EVENT CALLBACK %s %s', args, kw)
		Task(_callback, self, *args, **kw).start(0.10000000000000001)

	dbus_scan_progression = tasked(0.10000000000000001)()
	dbus_scan_service_found_callback = tasked(0.10000000000000001)()
	_update_services = selective_gui_updater('nb_video_services', 'nb_radio_services')()
	def tick_callback(self):
		pass

	def unregister_wyscan_callbacks(self):
		self.wyscanserver.errorCallback.unregister(self.dbus_error_callback)
		self.wyscanserver.eventCallback.unregister(self.dbus_event_callback)
		self.wyscanserver.scanEventCallback.unregister(self.dbus_scan_callback)
		self.wyscanserver.serviceUpdateCallback.unregister(self.dbus_scan_service_found_callback)
		self.wyscanserver.scanProgression.unregister(self.dbus_scan_progression)
		self.wyscanserver = None
		return None

	def _stop(self):
		self.scan_status = [0, 0, 0, 0]
		louie_send('scan_progress', sender=self, value=self['scan_progress'])
		louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
		ms = pygui_globs['menustack']
		try:
			self.unregister_wyscan_callbacks()
			if ChannelScanner._back_main_menu:
				ms.back_to_home()

	def process_stop(self):
		self.wyscanserver.StopScan(self.selected.antenna[7])

	def stop(self):
		Player.stop(self)
		if self._running:
			ChannelScanner._back_main_menu = True
			self.wyscanserver.StopScan(self.selected.antenna[7])
		if self._waiting_for_commit:
			self.wyscanserver.RollbackScan(self.selected.antenna[7])
			self.unregister_wyscan_callbacks()

	def prompt_for_commit(self):
		device_id = self.selected.antenna[7]
		self.scan_status[0] = self.scan_status[1]
		louie_send('scan_progress', sender=self, value=self['scan_progress'])
		louie_send('scan_progressbar', sender=self, value=self['scan_progressbar'])
		num_services = len(self.radio_services) + len(self.video_services)
		if num_services == 0 or ChannelScanner._back_main_menu:
			self.wyscanserver.RollbackScan(self.selected.antenna[7])
			self._stop()
		self._waiting_for_commit = True
		def _rollback():
			self.wyscanserver.RollbackScan(self.selected.antenna[7])
			ChannelScanner._back_main_menu = True
			self._stop()

		def _commit():
			if ChannelItem.player is not None:
				ChannelItem.player.clear_last_zap()
			self.wyscanserver.CommitScan(self.selected.antenna[7])
			user_config['tv']['last_scan_time'] = time()
			user_config.save()
			self._message_window.show()
			return None

		message = _('%(num_services)i channels found. Do you want to save them ?')
		values = {'num_services': num_services}
		button = Button(_('OK'), True)
		button.connect(_commit)
		cancel_button = Button(_('No'), False)
		cancel_button.connect(_rollback)
		w = ConfirmWindow(text=message % values, buttons=[button, cancel_button])
		Task(w.show).start(0.5)



